package com.mobi.Survey.lib.activities;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import com.mobi.Survey.lib.model.SurveyPojo;
import com.mobi.Survey.lib.model.User;

public abstract class AbstractAdapterSurveyList extends BaseAdapter
{
	protected List<SurveyPojo> surveys;
	protected LayoutInflater mInflater;
	protected SurveyListScreen surveyScreen;

	public void setData(List<SurveyPojo> surveys)
	{
		this.surveys = surveys;
	}

	public List<SurveyPojo> getData()
	{
		if (surveys == null)
			return new ArrayList<SurveyPojo>();

		return surveys;
	}

	public static final int getLayoutId()
	{
		int id = 0;

		switch (User.getInstance().getLayoutType())
		{
		case 0:
			id = LayoutIds.SURVEY_ROW_SMALL_0;
			break;

		case 1:
			id = LayoutIds.SURVEY_ROW_MEDIUM_1;
			break;

		case 2:
			id = LayoutIds.SURVEY_ROW_LARGE_2;
			break;

		case 3:
			id = LayoutIds.SURVEY_ROW_SMALL_ICON_3;
			break;
		case 4:
			id = LayoutIds.SURVEY_ROW_MEDIUM_ICON_4;
			break;
		case 5:
			id = LayoutIds.SURVEY_ROW_LARGE_ICON_5;
			break;
		default:
			id = LayoutIds.SURVEY_ROW_LARGE_ICON_5;
		}

		return id;
	}

	public void dispose()
	{
		if (surveys != null)
		{
			for (SurveyPojo survey : surveys)
			{
				if (survey.getBitmapIcon() != null
						&& !survey.getBitmapIcon().isRecycled())
				{
					survey.getBitmapIcon().recycle();
					survey.setBitmapIcon(null);
				}

			}
			surveys.clear();

		}
	}
}
